package com.liyi.letter.common.handler;

import com.liyi.letter.common.exception.LetterException;
import com.liyi.letter.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: letter_parent
 * @description 自定义异常返回信息
 * @author: tianwen
 * @create: 2023-06-01 17:58
 **/
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    /**
     * 自定义异常处理方法
     * @param e
     * @return
     */
    @ExceptionHandler(LetterException.class)
    @ResponseBody
    public Result error(LetterException e){
        return Result.fail(e.getMessage());
    }
}

